@include('widget.admin.adminnav',['url'=>'/index.php/admin/area/list','name'=>$type=='edit'?'编辑地区':'添加地区','title'=>'地区管理'])
<form class="form-horizontal" role="form" id="adminMessage">
    <div class="form-group">
        <label for="name" class="col-sm-2 control-label">地区名称</label>
        <input type="hidden" name="id" value="{{$id or 'new'}}">
        <div class="col-sm-6">
            <input type="text" class="form-control" id="name" value="{{$name or ''}}" placeholder="请输入地区名称">
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">活动分类</label>
        <div class="col-sm-6">
            <select class="form-control" id="getActivityId">
                <option disabled selected>无活动</option>
                @foreach($allActivity as $activity)
                    <option value="{{$activity->id}}" {{$activity->id==$activity_id?'selected':''}}>{{$activity->name}}</option>
                @endforeach
            </select>
        </div>
    </div>
    <div class="form-group">
        <label for="name" class="col-sm-2 control-label">地区简介</label>
        <div class="col-sm-6">
            <textarea cols="30" rows="10" class="form-control intro" placeholder="请输入地区简介" style="height: 100px;resize: none;">{{$intro or ''}}</textarea>
        </div>
    </div>
    <input type="hidden" id="id" value="{{$id or 'new'}}">
    <div class="form-group">
        @include('widget.upload',['bindBtn'=>'area-cover','uploadTitle'=>'上传封面',
        'backPath'=>'area-cover-path','showContent'=>'areaCover','defaultImg'=>isset($cover)?$cover:null,'editPath'=>isset($cover)?$cover:''])
    </div>
    <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10"  style="margin-top: 10px;">
            <button type="button" class="btn btn-primary" onclick="areaHandler()">提交</button>
            <button type="reset" class="btn btn-default">重填</button>
        </div>
    </div>
</form>
<script>
    function areaHandler(event) {
        var event = event || window.event;
        event.preventDefault(); // 兼容标准浏览器
        window.event.returnValue = false; // 兼容IE6~8
        var _data = {
            id : $("#id").val(),
            name: $("#name").val(),
            activity_id : $("#getActivityId  option:selected").attr('value'),
            intro : $(".intro").val(),
            cover : $("#area-cover-path").val()
        };
        var Url="/index.php/admin/area/save";
        dialog.confirm("确认保存？",function callback(){
            $.ajax({
                type:"post",
                data:_data,
                url:Url,
                dataType:"json",
                success:function(data){
                    if(data.res==1){
                        var _url="/index.php/admin/area/list";
                        dialog.success("操作成功！",_url);
                    }else{
                        dialog.error(data.msg);
                    }
                }
            });
        });
    }
</script>